<#if model??>
package ${model.packageName}.${model.model}<#if model.subModel??>.${model.subModel}</#if>.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import com.raising.framework.controller.BaseController;
import com.raising.framework.entity.ResultVo;
import com.raising.framework.interceptor.Page;
import com.raising.modules.sys.utils.DictUtils;
import com.raising.StaticParam;

import com.raising.utils.JStringUtils;
import com.raising.utils.JDateUtils;

import ${model.packageName}.${model.model}<#if model.subModel??>.${model.subModel}</#if>.entity.${model.className};
import ${model.packageName}.${model.model}<#if model.subModel??>.${model.subModel}</#if>.service.${model.className}Service;

/**
 * ${model.tableDesc} 控制器
 * @author ${model.authorNm}
 * @createTime ${model.createTime}
 */
@Controller
@RequestMapping("${"$"}{adminPath}/${model.model}/${model.className?uncap_first}")
public class ${model.className}Controller extends BaseController {

    @Autowired
    private ${model.className}Service ${model.className?uncap_first}Service;

    /**
     * 跳转至列表页面
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:view")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list() {
        return "${model.model}/${model.className?uncap_first}/list";
    }

    /**
     * 加载列表分页数据
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:view")
    @RequestMapping(value = "/getPage.json", method = RequestMethod.POST)
    public @ResponseBody ResultVo getPage(${model.className} ${model.className?uncap_first},Page<${model.className}> page,String searchKey) {
        page.setEntity(${model.className?uncap_first});
        page.setOrderBy(" a.id asc ");
        return new ResultVo(ResultVo.SUCCESS,"ok",${model.className?uncap_first}Service.getPage(page));
    }

    /**
     * 跳转新增页面
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:create")
    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public String create(${model.className} ${model.className?uncap_first},Model model) {
        model.addAttribute("${model.className?uncap_first}", ${model.className?uncap_first});
        // 是否可用
        model.addAttribute("yn", DictUtils.getDictList("DIM_YN"));
        model.addAttribute("showDateDefault", JDateUtils.getDate());
        return "${model.model}/${model.className?uncap_first}/add";
    }

    /**
     * 执行新增操作
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:create")
    @RequestMapping(value = "/create.json", method = RequestMethod.POST)
    @ResponseBody
    public ResultVo createJson(${model.className} ${model.className?uncap_first}) {
        ${model.className?uncap_first}.setStatus(StaticParam.VALID_STRING);
        ${model.className?uncap_first}Service.insert(${model.className?uncap_first});
        return new ResultVo(ResultVo.SUCCESS,ResultVo.CODE_OK,"新增成功",${model.className?uncap_first}.getId());
    }

    /**
     * 跳转更新页面
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:update")
    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public String update(String id, Model model) {
        ${model.className} ${model.className?uncap_first} = ${model.className?uncap_first}Service.get(id);
        model.addAttribute("${model.className?uncap_first}", ${model.className?uncap_first});
        // 是否可用
        model.addAttribute("yn", DictUtils.getDictList("DIM_YN"));
        return "${model.model}/${model.className?uncap_first}/edit";
    }

    /**
     * 执行更新操作
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:update")
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ResponseBody
    public ResultVo updateJson(${model.className} ${model.className?uncap_first}) {
        ${model.className?uncap_first}.setStatus(StaticParam.VALID_STRING);
        ${model.className?uncap_first}Service.update(${model.className?uncap_first});
        return new ResultVo(ResultVo.SUCCESS,ResultVo.CODE_OK,"更新成功",${model.className?uncap_first}.getId());
    }

    /**
     * 执行删除操作
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:delete")
    @RequestMapping(value = "/delete.json", method = RequestMethod.POST)
    @ResponseBody
    public ResultVo deleteJson(String id) {
        int result = ${model.className?uncap_first}Service.delete(id);
        if(result>0){
            return new ResultVo(ResultVo.SUCCESS,ResultVo.CODE_OK,"成功删除","");
        }else{
            return new ResultVo(ResultVo.SUCCESS,ResultVo.CODE_OK,"没有需要操作的数据","");
        }
    }

    /**
     * 跳转查看页面
     * @author ${model.authorNm}
     * @createTime ${model.createTime}
     */
    @RequiresPermissions("${model.model}:${model.className?uncap_first}:view")
    @RequestMapping(value = "/view", method = RequestMethod.GET)
    public String view(String id, Model model) {
        ${model.className} ${model.className?uncap_first} = ${model.className?uncap_first}Service.get(id);
        model.addAttribute("${model.className?uncap_first}", ${model.className?uncap_first});
        // 是否可用
        model.addAttribute("yn", DictUtils.getDictList("DIM_YN"));
        return "${model.model}/${model.className?uncap_first}/view";
    }

    <#--/**-->
     <#--* 统一置为0-->
     <#--* @author ${model.authorNm}-->
     <#--* @createTime ${model.createTime}-->
     <#--*/-->
    <#--public void set${model.className}PropertiesToZero(${model.className} ${model.className?uncap_first}){-->
    <#--<#list model.columns as column>-->
        <#--<#if column.columnName=="id">-->
        <#--<#elseif column.columnName=="createDate">-->
        <#--<#elseif column.columnName=="updateDate">-->
        <#--<#elseif column.columnName=="createBy">-->
        <#--<#elseif column.columnName=="updateBy">-->
        <#--<#elseif column.columnName=="status">-->
        <#--<#elseif column.columnName=="sort">-->
        <#--<#elseif column.columnName=="remarks">-->
        <#--<#elseif column.columnName=="orgId">-->
        <#--<#elseif column.columnName=="showDate">-->
        <#--<#else>-->
        <#--if(JStringUtils.isBlank(${model.className?uncap_first}.get${column.columnName?cap_first}())){-->
        <#--${model.className?uncap_first}.set${column.columnName?cap_first}("0");-->
        <#--}-->
        <#--</#if>-->
    <#--</#list>-->
    <#--}-->

}
</#if>